

function say() {
    alert("LC:1290. 二进制链表转整数");
}
say();


/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @return {number}
 */
var getDecimalValue = function(head) {
    //11:38-55

    //反转链表
    head = revrese(head)
    var res = 0
    var count = 0
    while(head){
        res += head.val * 2 ** count
        head = head.next
        count++
    }
    return res
};

function revrese(head){
    var current = head
    var pre = null

    while(current) {
        var last = current.next
        current.next = pre

        pre = current
        current = last
    }
    return pre
}
